package com.sz.mes.controller.warehouse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sz.mes.dto.warehouse.InstockRecordDTO;
import com.sz.mes.vo.InstockListVO;
import com.sz.mes.vo.warehouse.InstockRecordListVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.diboot.core.vo.*;
import com.diboot.iam.annotation.OperationCons;
import com.diboot.iam.annotation.BindPermission;
import com.diboot.iam.annotation.Log;
import com.sz.mes.entity.warehouse.LatticeGoods;
import com.sz.mes.dto.warehouse.LatticeGoodsDTO;
import com.sz.mes.vo.warehouse.LatticeGoodsListVO;
import com.sz.mes.vo.warehouse.LatticeGoodsDetailVO;
import com.sz.mes.service.warehouse.LatticeGoodsService;
import com.sz.mes.controller.BaseCustomCrudRestController;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import java.util.List;

/**
 * 货格对应商品表 相关Controller
 *
 * @author hem
 * @version 1.0
 * @date 2023-05-25
 * Copyright © szhs
 */
@RestController
@RequestMapping("/warehouse/latticeGoods")
@BindPermission(name = "货格对应商品表", code = "WarehouseLatticeGoods")
@Slf4j
public class LatticeGoodsController extends BaseCustomCrudRestController<LatticeGoods> {

    @Autowired
    private LatticeGoodsService latticeGoodsService;

    /**
     * 查询ViewObject的分页数据
     * <p>
     * url请求参数示例: /list?field=abc&pageIndex=1&orderBy=abc:DESC
     * </p>
     *
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    // @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @GetMapping("/list")
    public JsonResult getViewObjectListMapping(LatticeGoodsDTO queryDto, Pagination pagination) throws Exception {
        // QueryWrapper<LatticeGoods> queryWrapper = new QueryWrapper<>();
        // if (!StringUtils.isEmpty(queryDto.getGoodsCode())) {
        // queryWrapper.like("goods_code", queryDto.getGoodsCode());
        // } else if (!StringUtils.isEmpty(queryDto.getGoodsName())) {
        // queryWrapper.like("goods_name", queryDto.getGoodsName());
        // } else {
        // }
        // return super.getViewObjectList(queryDto, pagination, InstockListVO.class);
        return latticeGoodsService.getCommodityInventory(queryDto, pagination);
    }

    /**
     * 根据商品编码查询所有商品信息
     * </p>
     *
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    // @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @GetMapping("/getList")
    public JsonResult getViewObjectListMappingByGoodsCode(LatticeGoodsDTO queryDto, Pagination pagination) throws Exception {
        return super.getViewObjectList(queryDto, pagination, LatticeGoodsListVO.class);
    }

    /**
     * 根据资源id查询ViewObject
     *
     * @param id ID
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_DETAIL)
    // @BindPermission(name = OperationCons.LABEL_DETAIL, code = OperationCons.CODE_READ)
    @GetMapping("/{id}")
    public JsonResult getViewObjectMapping(@PathVariable("id") Long id) throws Exception {
        return super.getViewObject(id, LatticeGoodsDetailVO.class);
    }

    /**
     * 创建资源对象
     *
     * @param entity
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_CREATE)
    // @BindPermission(name = OperationCons.LABEL_CREATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/")
    public JsonResult createEntityMapping(@Valid @RequestBody LatticeGoods entity) throws Exception {
        return super.createEntity(entity);
    }

    /**
     * 根据ID更新资源对象
     *
     * @param entity
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_UPDATE)
    // @BindPermission(name = OperationCons.LABEL_UPDATE, code = OperationCons.CODE_WRITE)
    @PutMapping("/{id}")
    public JsonResult updateEntityMapping(@PathVariable("id") Long id, @Valid @RequestBody LatticeGoods entity) throws Exception {
        return super.updateEntity(id, entity);
    }

    /**
     * 根据id删除资源对象
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_DELETE)
    // @BindPermission(name = OperationCons.LABEL_DELETE, code = OperationCons.CODE_WRITE)
    @DeleteMapping("/{id}")
    public JsonResult deleteEntityMapping(@PathVariable("id") Long id) throws Exception {
        return super.deleteEntity(id);
    }

    /**
     * 根据货格id查询格子里面的商品
     *
     * @param id ID
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_DETAIL)
    // @BindPermission(name = OperationCons.LABEL_DETAIL, code = OperationCons.CODE_READ)
    @GetMapping("/getLatticeGoodsById/{id}")
    public JsonResult getLatticeGoodsById(@PathVariable("id") Long id) throws Exception {
        return latticeGoodsService.getLatticeGoodsById(id);
    }
}
